//
// Created by Administrator on 2025/3/11.
//

#include "Duotai.h"

#include <fstream>
#include <iostream>
#include <ostream>
#include <sstream>
#include <string.h>

using namespace std;

class shape {
protected:
    int width;
    int height;
    public:
    shape(int width, int height) : width(width), height(height) {
        std::cout << "Shape constructor" << std::endl;
    }
    virtual int getarea(){}
    virtual ~shape() {
        std::cout << "Shape destructor" << std::endl;
    }

};

class triangle:public shape {
    public:
    triangle(int width, int height) : shape(width, height) {
        std::cout << "Triangle constructor" << std::endl;
    }
    int getarea() override{

        int area = width * height;
        std::cout << "Triangle getarea : "<< area << std::endl;
        return area;
    }
    ~triangle() {
        std::cout << "Triangle destructor" << std::endl;
    }
};

class rectangle: public shape {
    public:
    rectangle(int width, int height) : shape(width, height) {
        std::cout << "Rectangle constructor" << std::endl;

    }
    int getarea() override {
        int area = width * height /2 ;
        std::cout << "rectangle getarea : "<< area << std::endl;
        return area;
    }
    ~rectangle() {
        std::cout << "Rectangle destructor" << std::endl;
    }
};

int write_file(string filename) {
    ofstream file(filename,ios::out|ios::app);
    string content[1000];
    string temp;
    for (int i=0;i <101;i ++) {
        temp = to_string(i);
        // cout << content[i] << endl;
        file<< temp  <<endl;
    }
    file.close();
    return 0;
}

int read_file(string filename){
    ifstream file(filename,ios::in);
    // char content[200];

    // for (int i=0;i <100;i ++) {
    //     file >> content;
    //     cout << content  <<endl;
    //     if (content[0] == '\0' ) {
    //         break;
    //     }
    // }
    stringstream content ;
    content << file.rdbuf();
    cout << content.str() <<endl;
    file.close();
    return 0;

}

int file_handle() {
    ofstream file;
    string filename = "file.txt";
    file.open(filename, ios::out|ios::app);
    char content[200];
    cout << "Enter content: ";

    cin.getline(content, 200);
    file<< content << endl;


    cout << "Enter content again: ";
    cin.getline(content, 200);

    // for (int i=0; i<strlen(content); i++) {
    //     content[i] = toupper(content[i]);
    // }

    // cin >> content;
    file<< content << endl;
    file.close();
    return 0;
}

int test_file() {
    string filename = "file.txt";
    write_file(filename);
    read_file(filename);
}

int mem1() {
    int *array=new int [10];

    //释放内存
    delete [] array;


}



int main0313() {
    // shape *s_ptr;
    // shape shape(1,1);
    //
    //
    //
    // triangle tr(10,20);
    // s_ptr = &tr;
    // s_ptr->getarea();
    //
    // rectangle rr(30,40);
    // s_ptr = &rr;
    // s_ptr->getarea();
    //
    // delete s_ptr;

    // file_handle();
    // test_file();
    mem1();
}